#roundpanel.py

from pyjamas.ui import HTMLPanel

class RoundPanel(HTMLPanel):
    def __init__(self, html, borderColor = None, bgColor = "#ffffff", cornerSize = "small"):
        if not borderColor:
            borderColor = bgColor
        if cornerSize.lower() != "small":
            templ = """
                <b class="b00f" style="border-color: @bc; background: @bc;"></b>
                <b class="b0f" style="border-color: @bc; background: @bg;"></b>
                <b class="b1f" style="border-color: @bc; background: @bg;"></b>
            """
        else:
            templ = """<b class="b1f" style="border-color: @bc; background: @bc;"></b>"""
        templ += """
                <b class="b2f" style="border-color: @bc; background: @bg;"></b>
                <b class="b3f" style="border-color: @bc; background: @bg;"></b>
                <b class="b4f" style="border-color: @bc; background: @bg;"></b>
                    <div class="contentf" style="border-color: @bc; background: @bg;">
                        <div style="padding: 0.5em;">
                            @2
                        </div>
                    </div>
                <b class="b4f" style="border-color: @bc; background: @bg;"></b>
                <b class="b3f" style="border-color: @bc; background: @bg;"></b>
                <b class="b2f" style="border-color: @bc; background: @bg;"></b>
            """
        if cornerSize.lower() != "small":
            templ += """
                <b class="b1f" style="border-color: @bc; background: @bg;"></b>
                <b class="b0f" style="border-color: @bc; background: @bg;"></b>
                <b class="b00f" style="border-color: @bc; background: @bc;"></b>        
            """
        else:
            templ += """<b class="b1f" style="border-color: @bc; background: @bc;"></b>"""
            
        newhtml = templ.replace("@2", html)
        newhtml = newhtml.replace("@bc", borderColor)
        newhtml = newhtml.replace("@bg", bgColor)
        
        HTMLPanel.__init__(self, newhtml)